/*
 * Copyright (c) sl All rights reserved.
 * 本软件源代码版权归sl所有,未经许可不得任意复制与传播.
 */
package com.sl.crawler.manager;

import com.sl.crawler.common.enums.EmYn;
import com.sl.crawler.dao.HouseDao;
import com.sl.crawler.dao.base.BaseDao;
import com.sl.crawler.domain.House;
import com.sl.crawler.manager.base.BaseManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sl
 */
@Service
public class HouseManager extends BaseManager<House, Long> {
    @Autowired
    private HouseDao houseDao;
    @Autowired
    private HouseDetailDayManager houseDetailDayManager;

    public BaseDao<House, Long> getDao() {
        return houseDao;
    }

    //自定义扩展
    public void saveOrUpdateHouseAndDetail(House house) {
        this.saveOrUpdateHouse(house);
        houseDetailDayManager.saveOrUpdateHouseDetailDay(house);
    }

    public void saveOrUpdateHouse(House house) {
        House houseParam = new House();
        houseParam.setHouseId(house.getHouseId());
        houseParam.setYn(EmYn.YES.value());
        House houseDb = this.selectOneEntry(houseParam);
        if (houseDb == null || houseDb.getId() == null) {
            this.insertEntry(house);
        } else {
            house.setId(houseDb.getId());
            this.updateByKey(house);
        }
    }
}